package com.elm_springboot_s.controller;

import com.elm_springboot_s.pojo.Business;
import com.elm_springboot_s.pojo.RespondMessage;
import com.elm_springboot_s.service.BusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business")
@Api(tags = "商家相关接口")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @GetMapping("/listBusinessByOrderTypeId")
    @ApiOperation("根据点餐分类编号查询所属商家信息")
    public RespondMessage<List<Business>> listBusinessByOrderTypeId(Integer orderTypeId) {
        try {
            List<Business> businesses = businessService.listBusinessByOrderTypeId(orderTypeId);
            return RespondMessage.success(businesses);
        } catch (Exception e) {
            return RespondMessage.error("查询商家信息失败：" + e.getMessage());
        }
    }

    @GetMapping("/getBusinessById")
    @ApiOperation("根据商家编号查询商家信息")
    public RespondMessage<Business> getBusinessById(Integer businessId) {
        try {
            Business business = businessService.getBusinessById(businessId);
            return RespondMessage.success(business);
        } catch (Exception e) {
            return RespondMessage.error("查询商家信息失败：" + e.getMessage());
        }
    }
} 